package com.ms.service.module.zone.action;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ms.game.bank.BankProcessor;
import com.ms.game.bank.message.BankBuyFeeRequest;
import com.ms.game.bank.message.BankRequest;
import com.ms.game.common.container.GameLimitInfo;
import com.ms.game.gmtool.PlayerDisableData;
import com.ms.game.gmtool.message.CAppleIapAskCashRequest;
import com.ms.game.gmtool.message.CAppleIapVerifyRequest;
import com.ms.game.gmtool.message.CApplyIAPOrderIDRequest;
import com.ms.game.gmtool.message.CApplyIAPVerifyRequest;
import com.ms.game.gmtool.message.SUpdatePlayerSwitchList;
import com.ms.game.itembox.ItemBox;
import com.ms.game.itembox.container.ItemBasic;
import com.ms.game.itembox.container.ItemSilentCard;
import com.ms.game.itembox.message.CUseBroadcastCardRequest;
import com.ms.game.itembox.message.CUseItemRequest;
import com.ms.game.itembox.message.SUseSilentCardNotify;
import com.ms.game.lobby.GameLobbyModule;
import com.ms.game.sendgift.db.LoadAllNotifyDCLAsync;
import com.ms.game.sendgift.message.SendGiftResponse;
import com.ms.player.Player;
import com.ms.player.PlayerSwitchList;
import com.ms.player.UpdateAttributeList;
import com.ms.player.message.SUpdatePlayerZoneDataByAttributeList;
import com.ms.service.error.ErrorCode;
import com.ms.service.module.analysis.message.ClientReportData;
import com.ms.service.module.commonsettings.CommonSettings;
import com.ms.service.module.zone.BasicZone;
import com.ms.service.module.zone.BlockType;
import com.ms.service.module.zone.message.CCashGoldTransactionDetailsRequest;
import com.ms.service.module.zone.message.CTmpCashTakeRequest;
import com.ms.service.module.zone.message.SClientReportRequest;
import com.ms.service.module.zone.module.BasicZoneModule;
import com.xpec.c4.game.character.PeriodSyncStatisInfo;
import com.xpec.c4.game.time.TimeSys;
import com.xpec.c4.game.utility.GUID;
import com.xpec.c4.game.utility.GameUtility;
import com.xpec.c4.message.ConstantCode;
import com.xpec.c4.message.MessageTypes;
import com.xpec.c4.service.annotations.MessageType;
import com.xpec.c4.service.annotations.Name;
import com.xpec.c4.service.common.BaseMessageAction;
import com.xpec.c4.service.contexts.Contexts;
import com.xpec.c4.service.contexts.ScopeType;
import com.xpec.c4.service.group.transportlayer.GroupMessage;
import com.xpec.c4.service.message.MessageAction;
import com.xpec.c4.service.module.BasicServiceModule;
import com.xpec.c4.service.module.ModuleName;
import com.xpec.c4.service.module.common.ItemInfoManager;
import com.xpec.c4.service.module.common.PlayerCommonInfoManager;

/**
 * 接收 zone 相關消息的 action
 * 
 * @author TW15010
 */
@Name(scopeType = ScopeType.SESSION)
public class BasicZoneAction extends BaseMessageAction {
	private static final Log log = LogFactory.getLog(BasicZoneAction.class);

	/**
	 * 收到 client 心跳消息要求
	 * 
	 * @param request
	 */
	@MessageType(typeCode = MessageTypes.C_PERIOD_SYNC_REQUEST)
	public void recvPeriodSyncRequest(long clientProcessTime) {
		Player player = getPlayer();

		if (player == null)
			return;

		if (player.getSyncStatisInfo() == null) {
			player.setSyncStatisInfo(new PeriodSyncStatisInfo());
		}

		// 進行加速器的相關檢查
		if (!player.getSyncStatisInfo().addSyncRecord(clientProcessTime)) {
			// 如果需要踢掉玩家寫在這裡
			// 玩家不合法 , 踢他
			// BasicZoneModule basicZoneModule = (BasicZoneModule) getModule();
			// BasicZone basicZone = basicZoneModule.getZone();
			//
			// log.error("kick by ilegal process Time: " + player);
			// basicZone.kickPlayer(player, CloseType.KICK_BY_ILEGAL);
			// return;
		}

		// 回覆 client 送來的心跳消息要求
		// 將 server 時間送回給 client 更新
		PeriodSyncStatisInfo.sendPeriodSyncResponse(player.getSessionID(), TimeSys.currentTimeMills());
	}


	/**
	 * 收到 client 使用道具的要求
	 * 
	 * @param request
	 *            使用要求資訊
	 */
	@MessageType(typeCode = MessageTypes.C_ZONE_USE_ITEM_REQUEST)
	public void recvUseItemRequest(CUseItemRequest request) {
		Player player = getPlayer();

		// 取得 zone module
		BasicServiceModule sm = getModule();
		if (!(sm instanceof BasicZoneModule)) {
			return;
		}

		BasicZoneModule zm = (BasicZoneModule) sm;
		if(zm.isStopTransaction()){						
			ItemBox.sendUseItemResponseToClient(player.getSessionID(), ErrorCode.GAME_SERVER_WAIT_TO_CLOSE ,player.getAccountId(), player.getGuid());				
			return;					
		}			

		int limitCode = GameLimitInfo.checkLimitByClassify(GameLimitInfo.ITEM_USE, player.getVip(),player.getLevel(), player.isVerifiedMember(), player.isTrialAccount(), player.getUplineCode());
		if(limitCode != GameLimitInfo.TRUE){
			int errorCode = GameLimitInfo.limitToErrorCode(limitCode);
			ItemBox.sendUseItemResponseToClient(player.getSessionID(), errorCode, player.getAccountId(), player.getGuid());
			return;
		}	
		
		BasicZone bz = zm.getZone();
		if(bz.isBlock(player.getGuid(), null)){
			ItemBox.sendUseItemResponseToClient(player.getSessionID(), ErrorCode.CANT_USE_ITEM_NOW, player.getAccountId(), player.getGuid());
			return;
		}
		
		//加到block list
		bz.putBlockList(player.getGuid(), null, BlockType.USE_ITEM);

		// 使用道具
		int res = player.getItemBox().useItem(zm, getModuleID(), "", player, request.getUseItemSn(), 1,
				request.getTargetPlayerName());
		
		// 傳錯誤碼
		if (res != ErrorCode.SUCCESS) {
			
			bz.removeBlockList(player.getGuid(), null);
			// 寫 log
			if (log.isErrorEnabled()) {
				// player <player name> use item <item name> fail
				// (<error description>).
				log.error("playse " + player + " use item " + request.getUseItemSn() + " fail ("
						+ ConstantCode.getName(ErrorCode.class, res) + ").");
			}

			ItemBox.sendUseItemResponseToClient(player.getSessionID(), res , player.getAccountId(), player.getGuid());
		}
	}
	
	
	@MessageType(typeCode = MessageTypes.C_ZONE_BATCH_CHANGE_GOLD_COIN_CARD_RQUEST)
	public void recvBatchChangeGoldCoinCardToGold(Object request){

		BasicServiceModule module = Contexts.getModule();
		if (module == null) {
			return;
		}
		
		BasicZoneModule zoneModule = (BasicZoneModule) module;

		BasicZone zone = zoneModule.getZone();
		if (zone == null) {
			return;
		}

		Player player = getPlayer();
		if (player == null) {
			return;
		}
		
		player.getItemBox().batchChangeGoldCoinCard(zoneModule, zoneModule.getModuleName(), "", player);
	}

	/**
	 * 收到另一個 zone 送來，對某人使用禁言卡的通知
	 * 
	 * @param notify
	 *            對某人使用禁言卡的通知
	 */
	@MessageType(typeCode = MessageTypes.S_ZONE_USE_SILENT_CARD_NOTIFY)
	public void recvUseSilentCardNotify(SUseSilentCardNotify notify) {
		if (notify == null) {
			return;
		}
		
		// 取得禁言卡資料
		ItemBasic item = ItemInfoManager.getInstance().getItem(notify.getItemId());
		if (item == null) {
			return;
		}

		if (!(item instanceof ItemSilentCard)) {
			return;
		}

		ItemSilentCard silentCard = (ItemSilentCard) item;

		// 使用
		silentCard.applyEffect(notify.getZoneId(), notify.getSourcePlayerName(), notify.getTargetGuid());
	}

	/**
	 * 收到 client 使用全頻卡的要求
	 * 
	 * @param request
	 *            要求內容
	 */
	@MessageType(typeCode = MessageTypes.C_ZONE_USE_BROADCAST_CARD_REQUEST)
	public void recvUseBroadcastCardRequest(CUseBroadcastCardRequest request) {
		if (request == null) {
			return;
		}

		BasicZone zone = GameUtility.getZone(getModuleID());
		if (zone == null) {
			return;
		}

		Player player = getPlayer();

		zone.onUseBroadcastCardRequest(player, request);
	}

	/**
	 * client 要求角色身上的道具清單
	 * 
	 * @param obj
	 */
	@MessageType(typeCode = MessageTypes.C_ZONE_GET_ITEM_LIST_REQUEST)
	public void recvGetItemListRequest(Object obj) {
		BasicZone zone = GameUtility.getZone(getModuleID());
		if (zone == null) {
			return;
		}

		Player player = getPlayer();

		zone.onGetItemListRequest(player);
	}
	
	
	@MessageType(typeCode = MessageTypes.C_ZONE_GET_ACCOUNT_ITEM_TO_PLAYER_REQUEST)
	public void recvGetItemFromAccountItemList(String accountItemSn){
		//先確認資料
		BasicZone zone = GameUtility.getZone(getModuleID());
		if (zone == null) {
			return;
		}

		BasicServiceModule basicServiceModule = (BasicServiceModule) Contexts.getModule();
		if (basicServiceModule == null) {
			return;
		}

		Player player = getPlayer();
		
		zone.onGetItemFromAccountItemList(basicServiceModule, player, accountItemSn);
	}
	
	/**
	 * 收到模擬玩家登入的要求
	 * 
	 * @param player
	 *            模擬要登入的玩家資料
	 */
	@MessageType(typeCode = MessageTypes.S_ZONE_FAKE_PLAYER_LOGIN)
	public void recvFakePlayerLogin(Player player) {
		if (player == null) {
			return;
		}

		BasicServiceModule basicModule = getModule();
		if (!(basicModule instanceof BasicZoneModule)) {
			return;
		}

		BasicZoneModule zoneModule = (BasicZoneModule) basicModule;
		BasicZone zone = zoneModule.getZone();
		zone.onLoginZoneGetPlayerDataFromDC(player.getGuid(), player, player.getSessionID());
	}
	
	
	@MessageType(typeCode = MessageTypes.C_BANK_CHANGE_POINT_TO_GOLD_REQUEST)
	public void changePointToGold(BankRequest request){
		BasicServiceModule basicModule = getModule();
		if (!(basicModule instanceof BasicZoneModule)) {
			return;
		}
		BasicZoneModule zoneModule = (BasicZoneModule) basicModule;
		BasicZone zone = zoneModule.getZone();
		GUID sessionId = sessionID;
		zone.changePointToGold(sessionId , request , zoneModule);
	}
	
	/*
	 * 收到 client 每日獎勵按鈕點擊時詢問每日獎勵的消息
	 */
	@MessageType(typeCode = MessageTypes.C_CONTINUE_REWARD)
	public void getContinueRewardInfo(GUID id){
		Player player = getPlayer();
		BasicServiceModule basicModule = getModule();
		if (!(basicModule instanceof BasicZoneModule)) {
			return;
		}
		BasicZoneModule zoneModule = (BasicZoneModule) basicModule;
		BasicZone zone = zoneModule.getZone();
		GUID sessionId = sessionID;
		
		zone.getContinueRewardInfo(player, sessionId);
	}
	
	/*
	 * 收到 client 領取每日獎勵
	 */
	@MessageType(typeCode = MessageTypes.C_GET_CONTINUE_REWARD)
	public void getContinueReward(int needReward){
		Player player = getPlayer();
		BasicServiceModule basicModule = getModule();
		if (!(basicModule instanceof BasicZoneModule)) {
			return;
		}
		BasicZoneModule zoneModule = (BasicZoneModule) basicModule;
		BasicZone zone = zoneModule.getZone();
		GUID sessionId = sessionID;
		
		zone.sendContinueRewardMessage(needReward, player, sessionId);
		
//		GameLobbyProcesser.sendContinueRewardMessage(needReward , player, sessionId);
	}
	
	
	
	/**
	 * GMTOOL設定線上玩家禁止送禮和原因
	 */
	@MessageType(typeCode = MessageTypes.S_GMTOOL_DISABLE_PLAYER_SEND_GIFT_TIME_REASON)
	public boolean updatePlayerDisableSendGiftTimeReason(PlayerDisableData data){
		
		BasicServiceModule basicModule = getModule();
		if (!(basicModule instanceof BasicZoneModule)) {
			return false;
		}
		
		BasicZoneModule zoneModule = (BasicZoneModule) basicModule;
		BasicZone zone = zoneModule.getZone();
		if (zone.updatePlayerDisableSendGiftTimeReason(data))
			return true;
		return false;
	}
	
	/**
	 * GmTool 通知Server主動去退不能送禮玩家送出去還沒被接收的東西
	 * */
	@MessageType(typeCode = MessageTypes.S_GMTOOL_CHECK_SEND_GIFT_TIME_OUT)
	public boolean checkGiftTimeout(PlayerDisableData data){
		BasicServiceModule basicModule = getModule();

		if (basicModule instanceof GameLobbyModule) {
			GameLobbyModule module = (GameLobbyModule) basicModule;
			SendGiftResponse response = new SendGiftResponse();

			Player playerData = module.getZone().getPlayer(data.getGuid());

			LoadAllNotifyDCLAsync loadData = new LoadAllNotifyDCLAsync();
			loadData.playerID = data.getGuid();
			loadData.playerIP = data.getDisableSendGiftReason();
			loadData.sessionID = null;
			basicModule.addCentralAsyncCommand(loadData, basicModule, playerData, response);
			return true;
		}
		return false;
	}
	
	/**
	 * 開啟儲值介面取得玩家點數和道具數量
	 */
	@MessageType(typeCode = MessageTypes.C_ZONE_OPEN_RECHAREGE_PAGE_REQUEST)
	public void openRechargePage(Object request) {
		BasicServiceModule basicModule = getModule();
		if (!(basicModule instanceof BasicZoneModule)) {
			return;
		}
		BasicZoneModule zoneModule = (BasicZoneModule) basicModule;
		BasicZone zone = zoneModule.getZone();

		zone.onOpenRechargePage(sessionID, zoneModule);
	}
	
	/**
	 * 包月
	 */
	@MessageType(typeCode = MessageTypes.C_BANK_MONTHLY_FEE_REQUEST)
	public void buyMonthlyFeeByPoint(Object request){
		BasicZoneModule basicModule = (BasicZoneModule)getModule();
		if (!(basicModule instanceof BasicZoneModule)) {
			return;
		}
		BankProcessor.OnBuyMonthlyFeeByPoint(sessionID, basicModule);
	}

	/**
	 * 包月/週
	 */
	@MessageType(typeCode = MessageTypes.C_BANK_BUY_FEE_REQUEST)
	public void buyFeeByPoint(BankBuyFeeRequest request){
		BasicZoneModule basicModule = (BasicZoneModule)getModule();
		if (!(basicModule instanceof BasicZoneModule)) {
			return;
		}
		BankProcessor.OnBuyWeeklyFeeByPoint(sessionID, basicModule, request);
	}
	
	/**
	 * 開啟儲值介面取得交易明細
	 */
	
	@MessageType(typeCode = MessageTypes.C_ZONE_CASH_GOLD_TRANSACTION_DETAIL_REQUEST)
	public void getCashGoldTransactionDetails(CCashGoldTransactionDetailsRequest request){
		BasicServiceModule basicModule = getModule();
		if (!(basicModule instanceof BasicZoneModule)) {
			return;
		}
		BasicZoneModule zoneModule = (BasicZoneModule) basicModule;
		BasicZone zone = zoneModule.getZone();
		zone.getCashGoldTransactionDetais(sessionID,zoneModule,request);
	}

	@MessageType(typeCode = MessageTypes.C_ITEM_REFINE_REQUEST)
	public void recvItemRefineRequest(String refineItemSn) {
		Player player = getPlayer();
		if (player == null) {
			return;
		}

		BasicZone zone = GameUtility.getZone(getModuleID());
		if (zone == null) {
			return;
		}

		zone.recvItemRefineRequest(player, refineItemSn);
	}
	
	@MessageType(typeCode = MessageTypes.C_ZONE_ROBOT_ADD_CASH_POINT_REQUEST)
	public void robotAddCashPoint(Long cashChangeValue) {
		BasicServiceModule basicModule = getModule();
		if (!(basicModule instanceof BasicZoneModule)) {
			return;
		}

		BasicZoneModule zoneModule = (BasicZoneModule) basicModule;

		Player player = getPlayer();

		BasicZone zone = GameUtility.getZone(getModuleID());
		if (zone == null) {
			return;
		}
		
		zone.onRobotAddCash(sessionID, zoneModule, player ,cashChangeValue);
	}
	
	@MessageType(typeCode = MessageTypes.C_ZONE_ROBOT_ADD_TRIAL_COIN_REQUEST)
	public void robotAddTrialCoin(Long cashChangeValue) {
		BasicServiceModule basicModule = getModule();
		if (!(basicModule instanceof BasicZoneModule)) {
			return;
		}

		BasicZoneModule zoneModule = (BasicZoneModule) basicModule;
		BasicZone zone = zoneModule.getZone();
		Player player = getPlayer();
		if (player == null) {
			return;
		}

		zone.onRobotAddTrialCoin(player);
	}
	

	/**
	 * 申請iap訂單id
	 */
	@MessageType(typeCode = MessageTypes.C_APPLY_IAP_ORDERID)
	public void iapApplyOrderID(CApplyIAPOrderIDRequest request)
	{
		BasicServiceModule basicModule = getModule();
		if (!(basicModule instanceof BasicZoneModule)) {
			return;
		}

		BasicZone zone = GameUtility.getZone(getModuleID());
		if (zone == null) {
			return;
		}
		
		zone.onIapApplyOrderID(sessionID, request);
	}
	
	
	/**
	 * 驗證各平台遊戲訂單
	 */
	@MessageType(typeCode = MessageTypes.C_VERIFY_IAP_DATA)
	public void iapBillingVerify(CApplyIAPVerifyRequest request)
	{
		BasicServiceModule basicModule = getModule();
		if (!(basicModule instanceof BasicZoneModule)) {
			return;
		}

		BasicZoneModule zoneModule = (BasicZoneModule) basicModule;

		BasicZone zone = GameUtility.getZone(getModuleID());
		if (zone == null) {
			return;
		}
		
		zone.onIapBillingVerify(sessionID, request);
	}
	
	/**
	 * 驗證各平台遊戲訂單
	 */
	@MessageType(typeCode = MessageTypes.C_ASK_GIVE_IAP_CASH)
	public void iapAskGiveCash(CApplyIAPVerifyRequest request)
	{
		BasicServiceModule basicModule = getModule();
		if (!(basicModule instanceof BasicZoneModule)) {
			return;
		}

		BasicZone zone = GameUtility.getZone(getModuleID());
		if (zone == null) {
			return;
		}
		
		zone.onIapAskGiveCash(sessionID, request);
	}
	
	/**
	 * 驗證蘋果
	 */
	@MessageType(typeCode = MessageTypes.C_APPLE_IAP_VERIFY)
	public void appleIapVerify(CAppleIapVerifyRequest request){
		BasicServiceModule basicModule = getModule();
		if (!(basicModule instanceof BasicZoneModule)) {
			return;
		}
		
		BasicZone zone = GameUtility.getZone(getModuleID());
		if (zone == null) {
			return;
		}
		
		zone.onAppleIapVerify(sessionID, request);
	}
	
	/**
	 * 驗證蘋果要錢
	 */
	@MessageType(typeCode = MessageTypes.C_APPLE_IAP_ASK_CASH)
	public void appleAakCash(CAppleIapAskCashRequest request){
		BasicServiceModule basicModule = getModule();
		if (!(basicModule instanceof BasicZoneModule)) {
			return;
		}
		
		BasicZone zone = GameUtility.getZone(getModuleID());
		if (zone == null) {
			return;
		}
		
		zone.onAppleAskCash(sessionID, request);
	}

	/**
	 * 用updateAttribute更新角色暫存資料
	 * @param request
	 */
	@MessageType(typeCode = MessageTypes.S_ZONE_UPDATE_PLAYER_ATTRIBUTE_DATA)
	public void updatePlayerDataByAttributeList(SUpdatePlayerZoneDataByAttributeList request){
		GUID playerGuid = request.getPlayerId();
		if(playerGuid == null){
			playerGuid = PlayerCommonInfoManager.getInstance().getPlayerGuidBySession(request.getPlayerSessionId());
			if(playerGuid == null){
				if(log.isInfoEnabled()){
					log.info("Player Not Online");
				}
				return;
			}
		}
		
		BasicServiceModule basicServiceModule = Contexts.getModule();
		if (basicServiceModule instanceof BasicZoneModule) {
			BasicZoneModule basicZoneModule = (BasicZoneModule) basicServiceModule;
			BasicZone basicZone = basicZoneModule.getZone();
			Player player = basicZone.getPlayer(playerGuid);
			if (player != null) {
				if (request.getUpdatedAttrList() != null) {
					UpdateAttributeList.applyUpdateListToPlayer(request.getUpdatedAttrList(), player);
				}

				if (request.getUpdateItemList() != null) {
					request.getUpdateItemList().applyToPlayer(player);
				}
			} else {
				if (log.isInfoEnabled()) {
					log.info("Player Not Found From Zone");
				}
			}
		}
	}

	/**
	 * 清除 zone 上 LoginPlayerList 內指定的 guid
	 * 
	 * @param playerGuid
	 */
	@MessageType(typeCode = MessageTypes.S_GMTOOL_REMOVE_GUID_FROM_ZONE_LOGIN_PLAYER_LIST)
	public void gmtoolRemoveGuidFromZoneLoginPlayerList(GUID playerGuid) {
		BasicServiceModule basicServiceModule = Contexts.getModule();
		if (basicServiceModule instanceof BasicZoneModule) {
			BasicZoneModule basicZoneModule = (BasicZoneModule) basicServiceModule;
			BasicZone basicZone = basicZoneModule.getZone();

			basicZone.removeGuidFromLoginPlayerList(playerGuid);
		}
	}
	
	/**
	 * 更新player身上的PlayerSwitchList資訊
	 * (GMTOOL那邊已經先有判斷玩家是否在線，但保險起見在收到消息之後再判斷一次)
	 * @param data
	 */
	@MessageType(typeCode = MessageTypes.S_GMTOOL_UPDATE_PLAYER_SWITCHLIST_REQUEST)
	public void gmtoolUpdatePlayerSwitchListRequest(SUpdatePlayerSwitchList data){

		BasicServiceModule basicServiceModule = Contexts.getModule();
		if (!(basicServiceModule instanceof BasicZoneModule)) {
			return;
		}
		BasicZoneModule basicZoneModule = (BasicZoneModule) basicServiceModule;
		BasicZone basicZone = basicZoneModule.getZone();
		//判斷要改的那個人在不在線上
		GUID playerId = GUID.parseUUID(data.getGuid());
		Player player = null;
		player = basicZone.getPlayer(playerId);
		if(player == null){
			return;
		}else{
			player.setPlayerSwitchList(data.getPlayerSwitchListJsonString());
		}
		
		//如果需要告訴CLIENT端PlayerSwitchList相關異動
		GUID sessionId = PlayerCommonInfoManager.getInstance().getSessionByPlayerGuid(playerId);
		if(sessionId == null){
			return;
		}		
		//判斷本次GMTOOL修改的內容
		if(data.getChangeSwitch().equals(PlayerSwitchList.clientReportString)){
			SClientReportRequest request = new SClientReportRequest();
			long endTime = player.getPlayerSwitchListClass().getClientReport().getEndTime().getTime();
			request.setEndTime(endTime);
			if(player.getPlayerSwitchListClass().getClientReport().isReporting()){
				request.setIsbegin(true);
			}
			else{
				request.setIsbegin(false);
			}
//等CLIENT接			MessageAction.sendMessage(sessionId, MessageTypes.S_CLIENT_REPORT_COMMAND, cmd);
		}
	}
	
	/**
	 * 收到客戶端報告，判斷是否開關開啟
	 * @param data
	 */	
	@MessageType(typeCode = MessageTypes.C_CLIENT_REPORT)
	public void OnRecieveClientReport(ClientReportData data){
		Player player = getPlayer();
		
		try{			
			if(player.getPlayerSwitchListClass().getClientReport().isReporting()){
				//交給analysis處理
				GroupMessage msg = new GroupMessage();
				msg.setMessageContent(data);
				msg.setDestModuleID(ModuleName.ANALYSIS);
				msg.setMessageType(MessageTypes.S_CLIENT_REPORT);
				MessageAction.sendMessage(msg);
			}
			//客戶端在時限之外送了訊息
			else{
				if(log.isErrorEnabled()){
					log.error("Client send a report out of the setting time which player guid is " + player.getGuid().toString()
							   + "the content is [ " + data.getReportContent() + " ]");
				}
			}
		}
		//沒經由後台修改PlayerSwitchList就送這個消息，代表客戶端可能被破解了
		catch (Exception e) {
			if(log.isErrorEnabled()){
				log.error(e + "\nClient send a report without permission which player guid is " + player.getGuid().toString()
						   + ", the content is [ " + data.getReportContent() + " ]\nPlayerSwitchList Json is: " + player.getPlayerSwitchList());
			}
		}
	}
	
	/**
	 * 客戶端請求獲得自己的opID
	 * @param obj
	 */
	@MessageType(typeCode = MessageTypes.C_GET_OP_ID_REQUEST)
	public void OnRecieveGetOPIDRequest(Object obj){
		BasicServiceModule basicServiceModule = Contexts.getModule();
		if (!(basicServiceModule instanceof BasicZoneModule)) {
			return;
		}
		BasicZoneModule basicZoneModule = (BasicZoneModule) basicServiceModule;
		
		Player player = getPlayer();
		if(player == null)
			return;
		
		GUID accountID = player.getAccountId();
		GUID sessionID = getSessionID();
		
		basicZoneModule.getZone().getAccountOPIDandResonse(accountID, sessionID);
	}
	
	/**
	 * 客戶端切換模式(前景或背景)
	 */
	@MessageType(typeCode = MessageTypes.C_CHANGE_DEVICE_FRONT_OR_BACKGROUND_MODE)
	public void OnRecieveClientChangeMode(Boolean isBackgroundMode){
		GUID sessionID = getSessionID();
		if(sessionID == null)
			return;
		
		PlayerCommonInfoManager.getInstance().setSessionInBackgroundMode(sessionID, isBackgroundMode);
	}
	
	@MessageType(typeCode = MessageTypes.C_GET_COMMON_SETTINGS_REQUEST)
	public void revClientGetCommonSettings(Object object){
		GUID sessionID = getSessionID();
		if(sessionID == null)
			return;
		
		BasicServiceModule basicServiceModule = getModule();
		if(basicServiceModule != null)
			CommonSettings.sendToClientAllSettings(basicServiceModule.getCommonSettings(), sessionID);
	}
	
	@MessageType(typeCode = MessageTypes.C_ZONE_CHECK_DAILY_SEND_REQUEST)
	public void revClientCheckDailySend(Object object) {
		GUID sessionID = getSessionID();
		if(sessionID == null){
			return;
		}
			
		Player player = getPlayer();
		if(player == null){
			return;
		}
		
		BasicServiceModule basicServiceModule = getModule();
		if(basicServiceModule != null) {
			BasicZoneModule basicZoneModule = (BasicZoneModule) basicServiceModule;
			basicZoneModule.getZone().onCheckDailySend(player, sessionID, basicZoneModule);
		}
	}
	
	/**
	 * 收到要求把暫存錢包的錢放到 player 上
	 * 
	 * @param request
	 */
	@MessageType(typeCode = MessageTypes.C_TMP_CASH_TAKE_REQUEST)
	public void recvTmpCashTakeRequest(CTmpCashTakeRequest request) {
		Player player = getPlayer();
		BasicServiceModule basicServiceModule = Contexts.getModule();
		if (basicServiceModule instanceof BasicZoneModule) {
			BasicZoneModule basicZoneModule = (BasicZoneModule) basicServiceModule;
			BasicZone basicZone = basicZoneModule.getZone();

			basicZone.recvTmpCashTakeRequest(player, request);
		}
	}
}
